package com.wiley.homePO;

import io.appium.java_client.android.AndroidDriver;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.io.IOException;
import java.net.MalformedURLException;

public class GuessYouLikePage extends BasePage {
	
	LoggerControler log;

	/**
	 * 页面元素
	 */
	//猜你喜欢
	public static final By guess_you_like_loc = By.name("猜你喜欢");
	
	//列表image
	public static final By guess_you_like_image_loc = By.id(BaseId + "image");
	
	//详情页面title
	public static final By guess_you_like_titel_tv_loc = By.id(BaseId + "title_tv");
	
	/**
	 * 操作方法
	 */
	//点击猜你喜欢
	public void clickGuessYouLike(){
		this.clickEle(guess_you_like_loc);
	}
	
	//循环访问image
	public void clickGuessYouLikeImage(){
		int imageSize = this.getElesLength(guess_you_like_image_loc);
		for(int i = 0; i < imageSize; i++){
			this.clickEles(guess_you_like_image_loc, i);
			log.info("该recipe名为："+this.getGuessRecipeName());
			driver.sendKeyEvent(4);
		}
	}

	//获取菜谱名
	public String getGuessRecipeName(){
		WebElement ele = this.findEle(guess_you_like_titel_tv_loc);
		return ele.getText();
	}
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 */
	public void guessYouLikeView(Class name) throws MalformedURLException {
		log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		this.clickGuessYouLike();
		log.info("点击进入猜你喜欢列表");
		this.clickGuessYouLikeImage();
		log.info("该case测试通过！");
	}
}
